package com.yyj.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.yyj.domain.Order;
import com.yyj.domain.User;
import com.yyj.domain.WaitPay;
import com.yyj.service.OrderService;

@Controller
public class OrderController {
@Autowired
private OrderService orderService;

@RequestMapping("/insertorder.do")
public String insertOrder(Order order,Model model,HttpServletRequest request) {
	int i=orderService.insertOrder(order);
	if(i>0) {
		WaitPay waitPay=new WaitPay();
		waitPay.setAccount(order.getAccount());
		waitPay.setGoods_id(order.getGoods_id());
	orderService.deletewaitpay(waitPay);
	}
	String account=order.getAccount();
	System.out.println(account);
	User user=(User) orderService.selectuser(account);
	User users=new User();
	users.setOrder_sum(user.getOrder_sum()+1);
	users.setConsume_sum(user.getConsume_sum()+order.getLump_sum());
	System.out.println(user.getOrder_sum()+1);
	System.out.println(user.getConsume_sum()+order.getLump_sum());
	users.setNickname(order.getAccount());
	orderService.updateuser(users);
	
	User user2=orderService.selectupdateafter(order.getAccount());
	request.getSession().setAttribute("user", user2);
	return "success";
}
@RequestMapping("/success.do")
public String success() {
	return "success";
}
}
